from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()
# 定义模型
class Teacher(db.Model):
    __tablename__ = 'teachers'
    teacher_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    title_id = db.Column(db.Integer, db.ForeignKey('titles.title_id'), nullable=False)
    college_id = db.Column(db.Integer, db.ForeignKey('colleges.college_id'), nullable=False)

    # add
    title = db.relationship('Title', backref='teachers', lazy=True)

class Title(db.Model):
    __tablename__ = 'titles'
    title_id = db.Column(db.Integer, primary_key=True)
    title_name = db.Column(db.String(100), nullable=False)
    teaching_limit = db.Column(db.Integer, nullable=False)

class College(db.Model):
    __tablename__ = 'colleges'
    college_id = db.Column(db.Integer, primary_key=True)
    college_name = db.Column(db.String(100), nullable=False)

class Course(db.Model):
    __tablename__ = 'courses'
    course_id = db.Column(db.Integer, primary_key=True)
    course_name = db.Column(db.String(100), nullable=False)
    college_id = db.Column(db.Integer, db.ForeignKey('colleges.college_id'), nullable=False)
    course_hours = db.Column(db.Integer, nullable=False)

class TeachingRecord(db.Model):
    __tablename__ = 'teaching_records'
    teacher_id = db.Column(db.Integer, db.ForeignKey('teachers.teacher_id'), primary_key=True)
    course_id = db.Column(db.Integer, db.ForeignKey('courses.course_id'), primary_key=True)
    is_teaching = db.Column(db.Boolean, nullable=False)
    teaching_count = db.Column(db.Integer, nullable=False)